#include "BillboardSceneNode.h"
#include "D3DTexture.h"

namespace ISNW
{
namespace scene
{
	void BillboardSceneNode::onRegisterSceneNode()
	{
		if(scenemanager)
		{
			updateVertexBuffer();
			
			scenemanager->registernodeforrendering(this,E_RT_DEFAULT);
		}

		ISceneNode::onRegisterSceneNode();
	}

	void BillboardSceneNode::render()
	{
		if(!isVisible) return;

		if(scenemanager)
		{
			if(Material.texturelayers[0].texture == 0)
			{
				Material.texturelayers[0].texture = new video::D3DTexture;

				Material.texturelayers[0].texture->filename = "earth.bmp";
				Material.texturelayers[0].texture->createtexturefromfile();
			}

			scenemanager->getdriver()->setTransform(video::E_WORLD,AbsoluteTransformation);

			scenemanager->getdriver()->setmaterial(Material);

			scenemanager->getdriver()->drawtriangles(vertex_buffer,video::STANDAND_VERTEX,4,indices_buffer,2);
		}
	}

} // end namespace scene
} // end namespace ISNW